List<string> doesn't update the UI when change occurs [WPF]
Posted
by
Hard Turner
on Stack Overflow
See other posts from Stack Overflow
or by Hard Turner
Published on 2012-12-13T23:02:47Z
Indexed on
2012/12/13
23:03 UTC
Read the original article
Hit count: 210
<ListBox x:Name="MainList" HorizontalAlignment="Left" Height="468" Margin="10,10,0,0" VerticalAlignment="Top" Width="100" ItemsSource="{Binding Items,Mode=TwoWay}" DisplayMemberPath="Name"/>
[Serializable()]
public class MYcontainer : INotifyPropertyChanged,ISerializable
{
private List<MYClass> _items = new List<MYClass>();
public List<MYClass> Items
{
get{ return _items;}
set { this._items =value;
OnPropertyChanged("Items");
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName = null)
{
var eventHandler = this.PropertyChanged;
if (eventHandler != null)
eventHandler(this, new PropertyChangedEventArgs(propertyName));
}
}
when i add an item to "Items" the UI doesnt update, the binding is working fine, since if i closed the window and opened it again, the new items appear correctly what am i doing wrong? i know if i used observablecollection it will work fine, but shouldn't it work with List<>? , i already have in another window a string[] property and it update fine
© Stack Overflow or respective owner